home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-25 | 9.7 KB | 428 lines | [TEXT/CWIE] |
- // ==================================================
- // CDateEditField.cp
- // Copyright (C) 1996-1997 Mizutori Tetsuya
- // July 4, 1996; February 3, 1997.
- // ==================================================
- // All documents are pretty-printed in 10-point Geneva font.
-
- #include <LDialogBox.h>
- #include <UDrawingState.h>
-
- #include "touchMeConstants.h"
- #include "CDateEditField.h"
- #include "UDateTime.h"
- #include "UDragDropSuit.h"
-
- const ResIDT rcrsr_DraggingHand = 1001;
-
-
- // --------------------------------------------------
- // • CreateDateEditFieldStream [static]
- // --------------------------------------------------
-
- CDateEditField *
- CDateEditField::CreateDateEditFieldStream(
- LStream * inStream )
- {
- return new CDateEditField( inStream );
- }
-
-
- // --------------------------------------------------
- // • CDateEditField
- // --------------------------------------------------
-
- CDateEditField::CDateEditField()
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // • CDateEditField(const CDateEditField&)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- const CDateEditField & inOriginal )
- : LEditField( inOriginal ), LListener( inOriginal ), LBroadcaster( inOriginal )
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // • CDateEditField(SPaneInfo&, ... , inHasWordWrap, ...)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- const SPaneInfo & inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Boolean inHasBox,
- Boolean inHasWordWrap,
- KeyFilterFunc inKeyFilter,
- LCommander * inSuper)
- : LEditField( inPaneInfo, inString, inTextTraitsID, inMaxChars,
- inHasBox, inHasWordWrap, inKeyFilter, inSuper)
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // • CDateEditField(SPaneInfo&, ... , inAttributes, ...)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- const SPaneInfo & inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Uint8 inAttributes,
- KeyFilterFunc inKeyFilter,
- LCommander * inSuper)
- : LEditField( inPaneInfo, inString, inTextTraitsID, inMaxChars,
- inAttributes, inKeyFilter, inSuper)
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // • CDateEditField(LStream*)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- LStream * inStream )
- : LEditField( inStream )
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // • ~CDateEditField
- // --------------------------------------------------
-
- CDateEditField::~CDateEditField()
- {
- }
-
-
- // --------------------------------------------------
- // • ListenToMessage
- // --------------------------------------------------
- void
- CDateEditField::ListenToMessage(
- MessageT inMessage,
- void * ioParam )
- {
- #pragma unused ( inMessage, ioParam )
-
- //PaneIDT thisPaneID = GetPaneID();
- //Int32 thisUserCon = GetUserCon();
-
- // Do not refresh the EditField if click is still in this EditField.
- //if ( inMessage == thisUserCon ) return;
-
- //RefreshEditField();
- }
-
-
- // --------------------------------------------------
- // • UserChangedText
- // --------------------------------------------------
-
- void
- CDateEditField::UserChangedText( void )
- {
- LEditField::UserChangedText();
-
- mHasChanged = true;
- }
-
-
- // --------------------------------------------------
- // • ClickSelf
- // --------------------------------------------------
-
- void
- CDateEditField::ClickSelf(
- const SMouseDownEvent & inMouseDown )
- {
- if ( DoDragText( inMouseDown.macEvent, inMouseDown.whereLocal ) ) return;
-
- LEditField::ClickSelf( inMouseDown );
-
- // Int32 thisUserCon = GetUserCon();
- // BroadcastMessage( (MessageT) thisUserCon, nil );
- }
-
-
- // --------------------------------------------------
- // • BeTarget
- // --------------------------------------------------
-
- void
- CDateEditField::BeTarget( void )
- {
- LEditField::BeTarget();
-
- // Int32 thisUserCon = GetUserCon();
- // BroadcastMessage( (MessageT) thisUserCon, nil );
- }
-
-
- // --------------------------------------------------
- // • DontBeTarget
- // --------------------------------------------------
-
- void
- CDateEditField::DontBeTarget( void )
- {
- LEditField::DontBeTarget();
-
- // Int32 thisUserCon = GetUserCon();
- // BroadcastMessage( (MessageT) thisUserCon, nil );
-
- long theSelStart, theSelEnd;
- GetSelect( theSelStart, theSelEnd );
- RefreshEditField();
- SetSelect( theSelStart, theSelEnd );
- }
-
-
- // --------------------------------------------------
- // • DoDragText
- // --------------------------------------------------
-
- Boolean
- CDateEditField::DoDragText(
- const EventRecord & inMacEvent,
- const Point inMousePosition )
- {
-
- // Change cursor shape to my 'grabbing hand'.
- // ::SetCursor( &(qd.arrow));
- CCrsrHandle theCursH = ::GetCCursor( rcrsr_DraggingHand );
- if ( theCursH != NULL ) {
- ::SetCCursor( theCursH );
- ::DisposeCCursor( theCursH );
- }
-
- OSErr err;
- Boolean result = false;
-
- TEHandle teH = GetMacTEH();
-
- RgnHandle hiliteRgn = ::NewRgn();
- err = ::TEGetHiliteRgn( hiliteRgn, teH );
- if ( ::PtInRgn( inMousePosition, hiliteRgn ) ) {
- Handle hText = (**teH).hText;
- unsigned char * textP = (unsigned char *) *hText + (**teH).selStart;
- long textLen = (**teH).selEnd - (**teH).selStart;
- ::HLock( hText );
- Boolean wasDroppedInTrash = false;
- result = UDragDropSuit::DragText( inMacEvent, hiliteRgn, textP, textLen, wasDroppedInTrash );
- if ( result && wasDroppedInTrash ) {
- if ( ::ZeroScrap() == noErr ) {
- ::TECut( teH );
- if ( ::TEToScrap() != noErr ) ::ZeroScrap();
- // RefreshEditField();
- }
- }
- ::HUnlock( hText );
- }
-
- if ( hiliteRgn != NULL ) ::DisposeRgn( hiliteRgn );
-
- // Change back the cursor shape to iBeam.
- LEditField::AdjustCursorSelf( inMousePosition, inMacEvent );
-
- return result;
- }
-
-
- // ==================================================
- // Common functions
- // ==================================================
-
- // --------------------------------------------------
- // • GetTEActive
- // --------------------------------------------------
-
- Boolean
- CDateEditField::GetTEActive( void )
- {
- TEHandle theTextEditH = GetMacTEH();
-
- return (Boolean) ( (**theTextEditH).active != 0 );
- }
-
-
- // --------------------------------------------------
- // • SetTEActive
- // --------------------------------------------------
-
- void
- CDateEditField::SetTEActive(
- const Boolean inStatus )
- {
- TEHandle theTextEditH = GetMacTEH();
-
- if ( inStatus ) ::TEActivate( theTextEditH );
- else ::TEDeactivate( theTextEditH );
-
- ::TEIdle( theTextEditH );
- }
-
-
- // --------------------------------------------------
- // • GetSelect
- // --------------------------------------------------
-
- void
- CDateEditField::GetSelect(
- long & outSelStart,
- long & outSelEnd )
- {
- TEHandle theTextEditH = GetMacTEH();
-
- outSelStart = (**theTextEditH).selStart;
- outSelEnd = (**theTextEditH).selEnd;
- }
-
-
- // --------------------------------------------------
- // • SetSelect
- // --------------------------------------------------
-
- void
- CDateEditField::SetSelect(
- const long inSelStart,
- const long inSelEnd )
- {
- TEHandle theTextEditH = GetMacTEH();
- ::TESetSelect( inSelStart, inSelEnd, theTextEditH );
- }
-
-
- // --------------------------------------------------
- // • GetText
- // --------------------------------------------------
-
- void
- CDateEditField::GetText(
- Str255 outString )
- {
- TEHandle theHandle = GetMacTEH();
-
- outString[0] = (**theHandle).teLength;
- ::BlockMoveData( *((**theHandle).hText), &outString[1], outString[0] );
- }
-
- // --------------------------------------------------
- // • SetText
- // --------------------------------------------------
-
- void
- CDateEditField::SetText(
- const Str255 inString )
- {
- TEHandle theHandle = GetMacTEH();
-
- ::TESetText( &inString[1], inString[0], theHandle );
-
- Refresh();
-
- mHasChanged = true;
- }
-
-
- // --------------------------------------------------
- // • SetTextAndRefresh
- // --------------------------------------------------
-
- void
- CDateEditField::SetTextAndRefresh(
- const Str255 inString )
- {
- SetText( inString );
- RefreshEditField();
- }
-
-
- // --------------------------------------------------
- // • SetDateTime
- // --------------------------------------------------
-
- void
- CDateEditField::SetDateTime(
- const unsigned long inDateTimeSeconds )
- {
- PaneIDT thisPaneID = GetPaneID();
- Str255 theDateString, theTimeString;
-
- UDateTime::SecondsToDateTimeString( inDateTimeSeconds, theDateString, theTimeString );
-
- switch ( thisPaneID ) {
- case kMain_CrTextEditDate:
- case kMain_MdTextEditDate:
- SetText( theDateString );
- break;
-
- case kMain_CrTextEditTime:
- case kMain_MdTextEditTime:
- SetText( theTimeString );
- break;
- }
-
- // Do not need refresh this EditField.
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // • RefreshEditField
- // --------------------------------------------------
-
- void
- CDateEditField::RefreshEditField( void )
- {
- PaneIDT thisPaneID = GetPaneID();
-
- // Do not refresh the EditField if text has not been changed.
- if ( ! mHasChanged ) return;
-
- // Refresh the EditField, and then reset the flag 'mHasChanged'.
- Str63 theStrDate="\p1", theStrTime="\p0";
- unsigned long theSeconds;
-
- switch ( thisPaneID ) {
- case kMain_CrTextEditDate:
- case kMain_MdTextEditDate:
- {
- GetText( theStrDate );
- UDateTime::DateTimeStringToSeconds(theStrDate,theStrTime,theSeconds);
- UDateTime::SecondsToDateTimeString(theSeconds,theStrDate,theStrTime);
- SetText( theStrDate );
- }
- break;
-
- case kMain_CrTextEditTime:
- case kMain_MdTextEditTime:
- {
- GetText( theStrTime );
- UDateTime::DateTimeStringToSeconds(theStrDate,theStrTime,theSeconds);
- UDateTime::SecondsToDateTimeString(theSeconds,theStrDate,theStrTime);
- SetText( theStrTime );
- }
- break;
- }
-
- mHasChanged = false;
- }
-
- // end of program
-